<template>
    <div>
        <Modal :title="modalTitle" v-model="modalVisible" :mask-closable='false' :width="600" :styles="{top: '100px'}">
            <Form ref="form" :model="form" :label-width="70" :rules="formValidate">
                <FormItem label="课程名称" prop="courseName">
                    <Input v-model="form.courseName" style="width:450px" placeholder="请输入课程名称"/>
                </FormItem>
                <FormItem label="兑换学分" prop="transferCredit">
                    <InputNumber v-model="form.transferCredit" style="width:450px" placeholder="请输入可兑换学分"/>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="text" @click="cancelUser">取消</Button>
                <Button type="primary" :loading="submitLoading" @click="handelSubmit">提交</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import {addTransfercourse, resetTransfercourse} from "@/api/bus";

    export default {
        name: "transfercourseDrawer",
        components: {},
        data() {
            return {
                type: 0,
                errorPass: "",
                deptLoading: false,
                modalTitle: "添加条件",
                submitLoading: false,
                modalVisible: false,
                stuItemList: [],
                workItemList: [],
                form: {
                    id: '',
                    certificateId: '',
                    courseName: '',
                    transferCredit: 1
                },
                formValidate: {
                    courseName: [{required: true, message: "课程名称不能为空", trigger: "blur"}],
                    transferCredit: [{required: true, type: 'number', message: "可兑换学分不能为空", trigger: "blur"}]
                },
            }
        },
        methods: {
            init() {

            },
            showDrawer(params) {
                this.modalVisible = true;
                if (params.id) {
                    this.form.id = params.id
                    this.form.certificateId = params.certificateId
                    this.form.courseName = params.courseName
                    this.form.transferCredit = params.transferCredit
                    this.modalTitle = "编辑可兑换课程";
                    this.form.transferCredit = params.transferCredit * 1
                } else {
                    this.$refs.form.resetFields();
                    this.modalTitle = "新增可兑换课程";
                    this.form.certificateId = params.certificateId
                    this.form.id = ''
                }
            },
            cancelUser() {
                this.modalVisible = false;
            },
            handelSubmit() {
                this.$refs.form.validate(valid => {
                    if (valid) {
                        this.submitLoading = true;
                        // 添加 避免编辑后传入id等数据 记得删除
                        addTransfercourse(this.form).then(res => {
                            this.submitLoading = false;
                            if (res.status === true) {
                                this.$Message.success("添加成功");
                                this.$parent.getDataList();
                                this.$parent.resetTransfercourse();
                                this.modalVisible = false;
                            }
                        });
                    }
                });
            }
        },
        mounted() {

        }
    }
</script>

<style>

</style>